package com.webchat.user.controller;

import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.domain.vo.request.CreateGroupRequestVO;
import com.webchat.domain.vo.response.AccountRelationResponseVO;
import com.webchat.domain.vo.response.UserBaseResponseInfoVO;
import com.webchat.domain.vo.response.WaitConfirmUserResponseVO;
import com.webchat.rmi.user.AccountRelationClient;
import com.webchat.user.service.relation.AccountRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
public class AccountRelationController implements AccountRelationClient {


    @Autowired
    private AccountRelationService accountRelationService;

    @Override
    public APIResponseBean<Boolean> subscribe(@PathVariable String sourceAccount,
                                              @PathVariable String targetAccount) {

        return APIResponseBeanUtil.success(accountRelationService.subscribe(sourceAccount, targetAccount));
    }

    @Override
    public APIResponseBean<Boolean> unsubscribe(@PathVariable String sourceAccount,
                                                @PathVariable String targetAccount) {

        return APIResponseBeanUtil.success(accountRelationService.unsubscribe(sourceAccount, targetAccount));
    }

    @Override
    public APIResponseBean<Boolean> confirmSubscribe(@PathVariable String confirmAccount,
                                                     @PathVariable Long relationId) {

        return APIResponseBeanUtil.success(accountRelationService.confirmSubscribe(confirmAccount, relationId));
    }

    @Override
    public APIResponseBean<Boolean> rejectSubscribe(@PathVariable String rejectAccount,
                                                    @PathVariable Long relationId) {

        return APIResponseBeanUtil.success(accountRelationService.rejectSubscribe(rejectAccount, relationId));
    }

    @Override
    public APIPageResponseBean<UserBaseResponseInfoVO> pageRelations(String account, Integer type, Integer pageNo, Integer pageSize) {

        return accountRelationService.pageRelations(account, type, pageNo, pageSize);
    }

    @Override
    public APIResponseBean<AccountRelationResponseVO> listRelations(@PathVariable String account) {

        return APIResponseBeanUtil.success(accountRelationService.listRelations(account));
    }

    @Override
    public APIResponseBean<List<WaitConfirmUserResponseVO>> listWaitConformUsers(@PathVariable String account) {

        return APIResponseBeanUtil.success(accountRelationService.listWaitConformUsers(account));
    }

    @Override
    public APIResponseBean<String> createChatGroup(@RequestBody CreateGroupRequestVO createGroupRequest) {

        return APIResponseBeanUtil.success(accountRelationService.createChatGroup(createGroupRequest));
    }
}
